﻿
using System.Data;
using NPOI.HSSF.UserModel;
using System;
using Common.Utilities.Excel.Validator;
using System.Collections.Generic;
using NPOI.SS.UserModel;

namespace Common.Utilities.Excel.Import.EventArgument
{
    /// <summary>
    /// Excel导入事件参数
    /// </summary>
    public class ExcelImportArgs : EventArgs
    {
        #region 属性
        /// <summary>
        /// Excel
        /// </summary>
        public Excel Excel { get; set; }

        /// <summary>
        /// 是否取消
        /// </summary>
        public bool Canceled
        {
            get;
            set;
        }

        /// <summary>
        /// 提供给开发者添加导入消息
        /// </summary>
        public ExcelMessageCollection ExcelMessages 
        { get; set; }
        #endregion

        #region 初始化
        public ExcelImportArgs()  
        {
            Canceled = false;
        }

        public ExcelImportArgs(Excel excel, ExcelMessageCollection excelMessages)
        {
            Canceled = false;
            Excel = excel;
            ExcelMessages = excelMessages;
        }
        #endregion
    }

    public class ExcelImportWorksheetArgs : EventArgs
    {
        #region 属性

        /// <summary>
        /// Excel中的Sheet
        /// </summary>
        public ISheet Sheet { get; protected set; }

        /// <summary>
        /// 此Sheet的配置节
        /// </summary>
        public Worksheet Worksheet { get; protected set; }

        ///// <summary>
        ///// 容器对象
        ///// </summary>
        //public DataTable DataTable { get; set; }

        /// <summary>
        /// 工作表状态, 截获事件后可以对其赋值
        /// </summary>
        public WorksheetStatus WorksheetStatus { get; set; }

        /// <summary>
        /// 提供给开发者添加导入消息
        /// </summary>
        public ExcelMessageCollection ExcelMessages
        { get; set; }
        #endregion

        #region 初始化

        public ExcelImportWorksheetArgs() { }

        public ExcelImportWorksheetArgs(ISheet sheet, Worksheet worksheet, ExcelMessageCollection excelMessages)
        {
            Sheet = sheet;
            Worksheet = worksheet;
            WorksheetStatus = WorksheetStatus.Continue;
            ExcelMessages = excelMessages;
        }
        #endregion
    }

    public class ExcelImportRowArgs : EventArgs
    {
        #region 属性

        /// <summary>
        /// 本行数据源
        /// </summary>
        public Dictionary<string, object> DataRow { get; set; }

        /// <summary>
        /// Excel中获取的行
        /// </summary>
        public IRow Row { get; protected set; }

        /// <summary>
        /// Excel中获取的行
        /// </summary>
        public ISheet Sheet { get; protected set; }

        /// <summary>
        /// 配置项
        /// </summary>
        public Worksheet Worksheet { get; protected set; }

        /// <summary>
        /// 行状态, 截获事件后可以对其赋值
        /// </summary>
        public RowStatus RowStatus { get; set; }

        /// <summary>
        /// 提供给开发者添加导入消息
        /// </summary>
        public ExcelMessageCollection ExcelMessages
        { get; set; }
        #endregion

        #region ctor
        public ExcelImportRowArgs()
        {
            RowStatus = RowStatus.Continue;
        }

        public ExcelImportRowArgs(Dictionary<string, object> dataRow, IRow row, ISheet sheet, Worksheet worksheet, ExcelMessageCollection excelMessages)
        {
            DataRow = dataRow;
            Row = row;
            Sheet = sheet;
            Worksheet = worksheet;
            RowStatus = RowStatus.Continue;
            ExcelMessages = excelMessages;
        }
        #endregion
    }

    public class ExcelImportItemArgs : EventArgs
    {
        #region 属性
        private int _rowIndex;
        /// <summary>
        /// 当前单元格的行索引号
        /// </summary>
        public int RowIndex
        {
            get { return _rowIndex; }
            protected set { _rowIndex = value; }
        }

        private int _colIndex;
        /// <summary>
        /// 当前单元格的列索引号
        /// </summary>
        public int ColumnIndex
        {
            get { return _colIndex; }
            protected set { _colIndex = value; }
        }

        /// <summary>
        /// 当前单元格的值
        /// </summary>
        private object _value;
        public object Value
        {
            get { return _value; }
            protected set { _value = value; }
        }

        /// <summary>
        /// 配置
        /// </summary>
        public DataColumn DataColumn
        {
            get;
            protected set;
        }

        /// <summary>
        /// 字符串验证结果
        /// </summary>
        public ValidatorResult ValidatorResult { get; set; }

        public CellStatus CellStatus { get; set; }

        /// <summary>
        /// Excel中的单元格
        /// </summary>
        public ICell Cell { get; protected set; }

        /// <summary>
        /// Excel中获取的行数据值，只会包含当前列和列前的数据
        /// </summary>
        public Dictionary<string, object>  DataRowValue { get; protected set; }

        #endregion

        #region 初始化
        public ExcelImportItemArgs() { }

        public ExcelImportItemArgs(int row, int col, object cellValue, DataColumn dataColumn, ICell cell, ValidatorResult validatorResult,  Dictionary<string, object> dataRowValue)
        {
            _rowIndex = row;
            _colIndex = col;
            _value = cellValue;
            CellStatus = CellStatus.Continue;
            DataColumn = dataColumn;
            Cell = cell;
            ValidatorResult = validatorResult;
            DataRowValue = dataRowValue;
        }
        #endregion
    }

}
